<template>
  <div class="system-log-page">
    <el-card class="system-log-card">
      <template #header>
        <div class="card-header">
          <span>日志管理</span>
          <el-button type="primary" @click="handleAdd" v-if="hasPerm('system:log:add')">新增</el-button>
        </div>
      </template>
      
      <el-table :data="dataList" style="width: 100%">
        <el-table-column prop="code" label="编号" width="120" />
        <el-table-column prop="name" label="名称" width="150" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="getStatusType(scope.row.status)">
              {{ getStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" width="120" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleView(scope.row)" v-if="hasPerm('system:log:view')">查看</el-button>
            <el-button size="small" type="primary" @click="handleEdit(scope.row)" v-if="hasPerm('system:log:edit')">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)" v-if="hasPerm('system:log:delete')">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { hasPerm } from '@/utils/permission'
import { ElMessage } from 'element-plus'

const dataList = ref([])

const getStatusType = (status) => {
  const statusMap = {
    'active': 'success',
    'inactive': 'danger',
    'pending': 'warning'
  }
  return statusMap[status] || 'info'
}

const getStatusText = (status) => {
  const statusMap = {
    'active': '启用',
    'inactive': '禁用',
    'pending': '待审核'
  }
  return statusMap[status] || '未知'
}

const handleAdd = () => {
  ElMessage.info('新增日志管理功能')
}

const handleView = (row) => {
  ElMessage.info(`查看：${row.code}`)
}

const handleEdit = (row) => {
  ElMessage.info(`编辑：${row.code}`)
}

const handleDelete = (row) => {
  ElMessage.info(`删除：${row.code}`)
}

onMounted(() => {
  // 模拟数据
  dataList.value = [
    {
      code: '001',
      name: '示例数据1',
      status: 'active',
      createDate: '2025-07-30'
    },
    {
      code: '002',
      name: '示例数据2',
      status: 'inactive',
      createDate: '2025-07-29'
    },
    {
      code: '003',
      name: '示例数据3',
      status: 'pending',
      createDate: '2025-07-28'
    }
  ]
})
</script>

<style scoped>
.system-log-page {
  padding: 20px;
}

.system-log-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>